package coms.service;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import coms.ejb.sessionbean.*;

public class BusinessDelegate {
	private ReviewBeanRemote reviewBean = null; 
	private ConferenceBeanRemote conferenceBean = null;
	private FileBeanRemote fileBean = null;
	private UserBeanRemote userBean = null;
	private ConferenceItemBeanRemote conferenceItemBean = null;
	private PaymentBeanRemote paymentBean = null;
	
	public BusinessDelegate(){
		try {
			reviewBean = lookupReviewBean();
			conferenceBean = lookupConferenceBean();
			fileBean = lookupFileBean();
			userBean = lookupUserBean();
			conferenceItemBean = lookupConferenceItemBean();
			paymentBean = lookupPaymentBean();
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}
	
	private ReviewBeanRemote lookupReviewBean() throws NamingException{
		EJBLocator locator = EJBLocator.getInstance();
		return locator.lookupReviewBean();
	}
	
	private ConferenceBeanRemote lookupConferenceBean() throws NamingException{
		EJBLocator locator = EJBLocator.getInstance();
		return locator.lookupConferenceBean();
	}
	
	
	private FileBeanRemote lookupFileBean() throws NamingException{
		EJBLocator locator = EJBLocator.getInstance();
		return locator.lookupFileBean();
	}
	
	private UserBeanRemote lookupUserBean() throws NamingException{
		EJBLocator locator = EJBLocator.getInstance();
		return locator.lookupUserBean();
	}
	
	private ConferenceItemBeanRemote lookupConferenceItemBean() throws NamingException{
		EJBLocator locator = EJBLocator.getInstance();
		return locator.lookupConferenceItemBean();
	}
	private PaymentBeanRemote lookupPaymentBean() throws NamingException{
		EJBLocator locator = EJBLocator.getInstance();
		return locator.lookupPaymentBean();//(PaymentBeanRemote) ctx.lookup("java:app/coms-ejb/PaymentBean!coms.ejb.sessionbean.PaymentBeanRemote");		
	}
	
	public Object getBean(String beanName){
		
		if (beanName == "reviewBean") {
			return reviewBean;
			
		}else if (beanName == "conferenceBean"){
			return conferenceBean;
			
		}else if (beanName == "fileBean"){
			return fileBean;
			
		}else if (beanName == "userBean"){
			return userBean;
			
		}else if (beanName == "conferenceItemBean"){
			return conferenceItemBean;
			
		}else if (beanName == "PaymentBean"){
			return paymentBean;
		}else{
			return null;
		}
	}
	
}
